import re


def paragraph_generator(file_path):
    with open(file_path, encoding="utf8") as input_file:
        content = ''
        addFlag = False
        for line in input_file:
            if "_Kept in shorthand._" in line:
                addFlag = True
                continue

            if addFlag:
                content += line

        paragraphs = re.split(r'\n\s*\n', content)
        for paragraph in paragraphs:
            paragraph = paragraph.strip()
            if paragraph:
                yield paragraph


def tokenizer(text):
    words = re.findall(r'\b[a-z][a-zA-Z]{2,}\b', text)
    for word in words:
        if word:
            yield word


path_to_dracula = "dracula.txt"
paragraphs = paragraph_generator(path_to_dracula)

word_count = {}
for paragraph in paragraphs:
    for word in tokenizer(paragraph):
        if word in word_count:
            word_count[word] += 1
        else:
            word_count[word] = 1

with open('word_count.txt', 'w', encoding='utf8') as output_file:
    for word, count in word_count.items():
        output_file.write(f'{word}:{count}\n')

